﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;

namespace UI
{
    public class UIFieldRunMapTeamTemplate : MonoBehaviour
    {
        public HeroIcon heroIcon;
        public UILabel lbLv;
        public UILabel lbName;
        public UILabel lbUnion;
        public UILabel lbPower;
        public GameObject leaderFlag;
        public GameObject leaderBtn;
        public GameObject memberBtn;

        TeamMember member;

        public void Init(TeamMember member,bool leader)
        {
            this.member = member;
            this.lbLv.text = TableTextBlo.GetText("level") + member.level;
            this.lbName.text = member.nickName;
            this.lbUnion.text = member.state== BOOL.TRUE ? TableTextBlo.GetText("union_team_same") : TableTextBlo.GetText("union_team_diff");
            this.lbPower.text = member.fightPower + "";
            this.heroIcon.SetHeroWithId(member.heroId);
            this.leaderFlag.SetActive(leader);
            if (leaderBtn != null)
                this.leaderBtn.SetActive(leader);
            if (memberBtn != null)
                this.memberBtn.SetActive(!leader);
        }

        /// <summary>
        /// 替人
        /// </summary>
        public void OnKickMember()
        {
            var str = TableTextBlo.GetText("field_tick_member");
            var str0 = member.nickName;
            var str1 = string.Format(str, str0);
            var str2 = TableTextBlo.GetText("field_group_tick_out");

            BoxManager.CreateMessageBoxWithCofirmAndCancelButton(str1, true, (b) =>
            {
                if (b)
                {
                    var room = Room.RoomManager.currentRoom as Room.RoomField;
                    var net = room.netManager as Room.RoomNetField;
                    if (net != null)
                    {
                        net.SendCSTeamKick(member.playerId);
                    }
                }
            }, str2);
        }

        /// <summary>
        /// 解散
        /// </summary>
        public void OnDisbandTeam()
        {
            var str = TableTextBlo.GetText("field_dismiss_team");
            BoxManager.CreateMessageBoxWithCofirmAndCancelButton(str, true, (b) =>
            {
                if (b)
                {
                    var room = Room.RoomManager.currentRoom as Room.RoomField;
                    var net = room.netManager as Room.RoomNetField;
                    if (net != null)
                    {
                        net.SendCSDisbandTeam();
                    }
                }
            },TableTextBlo.GetText("field_group_ex"));
        }
    }
}